package com.mlk.core.util;

import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook;

import java.io.IOException;
import java.io.OutputStream;

/**
 * Excle下载工具类
 *
 * @author xulu
 */
@Slf4j
public class ExcleDownUtils extends FileDownUtils {

    private ExcleDownUtils() {
    }

    /**
     * Excle的下载
     *
     * @param fileName
     * @param workbook
     */
    public static void download(String fileName, Workbook workbook) {
        setHeader(fileName);
        OutputStream out = null;
        try {
            workbook.write(out = ServletUtils.getResponse().getOutputStream());
        } catch (IOException e) {
            log.error("file download exception {}", e);
        } finally {
            if (workbook != null) {
                try {
                    workbook.close();
                } catch (IOException e) {
                    // do nothing
                }
            }
        }
    }
}
